# -*- coding: utf-8 -*-

from WSResult import WSResult

class PreResult(WSResult):
    results = {}

    def as_string(self):
        result_str = ''

        if self.results['ns']:
            result_str += 'Interest domain names:\n'
            for name in self.results['ns']:
                result_str += '  {0}\n'.format(name)

        if self.results['powered_by']:
            result_str += '"Powered by" strings:\n'
            for name in self.results['powered_by']:
                result_str += '  {0}\n'.format(name)

        if self.results['robots_txt']:
            result_str += 'robots.txt:\n'
            result_str += '  {0}\n'.format(self.results['robots_txt'])

        result_str += 'Server{0} RESPONSE 404 on non exists DIRS requests\n'.\
                      format(' NOT' if not self.results['nf']['dirs'] else '')
        result_str += 'Server{0} RESPONSE 404 on non exists FILES requests\n'.\
                      format(' NOT' if not self.results['nf']['files'] else '')

        if self.results['svn']:
            result_str += 'SVN objects:\n'
            for name in self.results['svn']:
                result_str += '  {0}\n'.format(name)

        if self.results['dafs_dirs']:
            result_str += 'Interests dirs:\n'
            for name in self.results['dafs_dirs']:
                result_str += '  {0}\n'.format(name)

        if self.results['dafs_files']:
            result_str += 'Interests files:\n'
            for name in self.results['dafs_files']:
                result_str += '  {0}\n'.format(name)

        if self.results['title_and_encoding']:
            result_str += 'Page title stands before meta-tag with encoding (may help with UTF-7 XSS)\n'

        if self.results['headers']:
            result_str += 'Interests headers:\n'
            for header in self.results['headers']:
                result_str += "  {0}: {1}\n".format(header['name'], header['value'])

        return result_str

    def put(self, type, data):
        self.results[type] = data


